solve law of cosines